<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;
class OrdersController extends Controller
{
    public function index(Request $request)
    {
    	$where = [];
    	//实例化要操作的表
        $db = DB::table('orders');
        $db->join('order_goods','orders.id','=','order_goods.order_id')
        ->select('orders.*','order_goods.*')->get();
    	//判断有没有搜索username字段的值
    	if($request->has('order_num')){
    		// 获取要搜索的username字段的值
    		$username = $request->input('order_num');
    		//添加where模糊匹配条件
    		$db->where('order_num','like',"%{$order_num}%");
    		$where['order_num'] = $order_num;
    	}
    	
    	// 分页
    	$list = $db->paginate(3);
    	//加载模板
    	return view('admin.order.index',['list'=>$list,'where'=>$where]);
    }

    public function destroy($id)
    {
        //dd($id);
    	$row = DB::table('order_goods')->where('id',$id)->delete();
        // dd($row);
    	if($row>0){
    		return redirect('admin/orders');
    	}
    }
}
